import requests
import aiohttp
import asyncio

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0',
    'cookie':'fullscreengg=1; fullscreengg2=1; qgqp_b_id=337b67ed604375d1f8b104c8d5b52d0a; st_nvi=29ehJ2oAEoo5moEaN19v439f1; st_si=26059926489090; st_asi=delete; nid=0e7f3ff517f931bd0c850e267b969384; nid_create_time=1762236217313; gvi=4-VRUZpNUyp2UfUbkioX4e7ac; gvi_create_time=1762236217313; wsc_checkuser_ok=1; st_pvi=16113878900121; st_sp=2025-11-04%2014%3A03%3A37; st_inirUrl=; st_sn=4; st_psi=20251104154815358-113200301321-6582996104',
    'Referer': 'https://quote.eastmoney.com/center/gridlist.html'
}

# # 第一种
#
# urls = [f'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn={i}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb' for i in range(1, 274)]
# for url in urls:
#     response = requests.get(url, headers=headers)
#     print(response.json())


# # 第二种
# async def fetch(session, url):
#     async with session.get(url) as response:
#         await asyncio.sleep(1)
#         response = await response.json()
#         print(response)
#
# async def main():
#     async with aiohttp.ClientSession(headers=headers) as session:
#         urls = [f'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn={i}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb'for i in range(1, 274)]
#         tasks = [fetch(session, url) for url in urls]
#         await asyncio.gather(*tasks)
#
# asyncio.run(main())

# 多线程
import threading

def fetch(url):
    response = requests.get(url, headers=headers)
    print(response.json())


def main():
    threads = []
    urls = [f'https://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fs=m%3A0%2Bt%3A6%2Bf%3A!2%2Cm%3A0%2Bt%3A80%2Bf%3A!2%2Cm%3A1%2Bt%3A2%2Bf%3A!2%2Cm%3A1%2Bt%3A23%2Bf%3A!2%2Cm%3A0%2Bt%3A81%2Bs%3A262144%2Bf%3A!2&fields=f12%2Cf13%2Cf14%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152%2Cf5%2Cf6%2Cf7%2Cf15%2Cf18%2Cf16%2Cf17%2Cf10%2Cf8%2Cf9%2Cf23&fid=f3&pn={i}&pz=20&po=1&dect=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb'for i in range(1, 274)]
    for url in urls[0:3]:
        thread = threading.Thread(target=fetch, args=(url, ))
        thread.start()
        threads.append(thread)

    for thread in threads:
        thread.join()

if __name__ == '__main__':
    main()























































